package com.photoeditor.demo.model.face;

import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.photoeditor.R;
import com.photoeditor.demo.model.bean.EthnicityBean;
import com.photoeditor.demo.util.FontUtil;

import java.util.ArrayList;

/**
 * Created by @author winn on 2018/10/30.
 */

public class EthnicitySelectAdapter extends BaseMultiItemQuickAdapter<EthnicityBean, BaseViewHolder> {
    public static String OTHER_VALUE = "Other";

    private String mSelectedName = "";

    public EthnicitySelectAdapter() {
        super(new ArrayList<EthnicityBean>());
        addItemType(EthnicityBean.ETHNICITY_TYPE_PARENT, R.layout.item_ethnicity_parent);
        addItemType(EthnicityBean.ETHNICITY_TYPE_CHILD, R.layout.item_ethnicity_child);
    }

    @Override
    public long getItemId(int position) {
        return super.getItemId(position);
    }

    @Override
    protected void convert(BaseViewHolder helper, EthnicityBean item) {
        int itemViewType = helper.getItemViewType();
//        final EthnicityBean bean = item;
        TextView tvName = helper.getView(R.id.name);
        helper.addOnClickListener(R.id.name);
        tvName.setTag(item);
        tvName.setSelected(item.isSelAble());
        if (TextUtils.equals(item.getItemName(), mSelectedName)){
            tvName.setTextColor(mContext.getResources().getColor(R.color.text_ethnicity_introdution_tab_2));
//            FontUtil.setCustomFontHeavy(tvName);
        } else {
            tvName.setTextColor(mContext.getResources().getColor(R.color.text_ethnicity_introdution_content));
            FontUtil.setCustomFontMedium(tvName);
        }
        switch (itemViewType) {
            case EthnicityBean.ETHNICITY_TYPE_PARENT:
                String itemName = item.getItemName();
                tvName.setText(itemName);
                helper.addOnClickListener(R.id.icon);
                ImageView imageView = helper.getView(R.id.icon);
                imageView.setSelected(item.isExpand());
                if (item.isHasChild()){
                    imageView.setVisibility(View.VISIBLE);
                } else {
                    imageView.setVisibility(View.GONE);
                }
//                }
//                imageView.setVisibility(hasChild ? View.VISIBLE : View.INVISIBLE);
                break;
            case EthnicityBean.ETHNICITY_TYPE_CHILD:
                //name.setText(Html.fromHtml("<u>" + bean.getItemName() + "</u>"));
                tvName.setText(item.getItemName());
                break;
            default:
                break;
        }
    }

    public void setSelectedName(String selectedName) {
        mSelectedName = selectedName;
    }
}
